home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / Blitting Class Library / Blitting Headers / GWorldSetter.h < prev    next >
Encoding:
Text File  |  1995-10-29  |  933 b   |  45 lines  |  [TEXT/CWIE]

  1. // GWorldSetter.h, GWorld setter and restorer using the "resource acquisition
  2. //    is initialization" technique, see 9.4 of Stroustrup.
  3.  
  4. // copyright © 1995, Macneil Shonle. All rights reserved.
  5.  
  6. #ifndef __GWORLDSETTER__
  7. #define __GWORLDSETTER__
  8.  
  9. #ifndef __QDOFFSCREEN__
  10. #include <QDOffscreen.h>
  11. #endif
  12.  
  13.         // class GWorldSetter
  14. class GWorldSetter {
  15. public:
  16.     GWorldSetter(CGrafPtr, GDHandle =nil);
  17.     GWorldSetter(WindowRef);
  18.     ~GWorldSetter();
  19.  
  20. private:
  21.     CGrafPtr origPort;
  22.     GDHandle origDev;
  23. };
  24.  
  25. // sets the port to parameters
  26. inline GWorldSetter::GWorldSetter(CGrafPtr port, GDHandle gdh)
  27. {
  28.     ::GetGWorld(&origPort, &origDev);
  29.     ::SetGWorld(port, gdh);
  30. }
  31.  
  32. // sets the port to parameter
  33. inline GWorldSetter::GWorldSetter(WindowRef port)
  34. {
  35.     ::GetGWorld(&origPort, &origDev);
  36.     ::SetGWorld(CGrafPtr(port), GetMainDevice());
  37. }
  38.  
  39. // sets the port back to original
  40. inline GWorldSetter::~GWorldSetter()
  41. {
  42.     ::SetGWorld(origPort, origDev);
  43. }
  44.  
  45. #endif